#pragma once

#include <fstream>
#include <iostream>
#include <cmath>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include "../include/common.hpp"
#include "./track.cpp"
#include "./control.cpp"
#include "./motion.cpp"
#include "./circle.cpp"
#include "./rescue.cpp"
#include "./danger.cpp"
#include "./zebracrossing.cpp"
#include "./racing.cpp"

using namespace cv;
using namespace std;

class imgprocess
{
public:

    /**
	 * @brief 图像二值化
	 *
	 * @param frame	输入原始帧
	 * @return Mat	二值化图像
	 */
	Mat binaryzation(Mat &frame)
	{
		//灰度图在这
		Mat imageGray, imageBinary;
		cvtColor(frame, imageGray, COLOR_BGR2GRAY); // RGB转灰度图
		threshold(imageGray, imageBinary, 0, 255, THRESH_OTSU); // OTSU二值化方法
		return imageBinary;
	}
	//Mat转数组
    void mat_to_arry(track & track)
    {
        for (int i = 0; i < ROWSIMAGE; i ++){
            for (int j = 0; j < COLSIMAGE; j ++){
                track.index[i][j] = track.binary_mat.at<uchar>(i, j);
            }
        }
        return;
    }
	//传入单张图像
	void display(Motion & motion,control & control,track & track, string string)
	{
		Mat binary_mat_3channel;
		cvtColor(track.binary_mat, binary_mat_3channel, cv::COLOR_GRAY2BGR); 
		track.drawImage(binary_mat_3channel);
		control.draw_mid_line(binary_mat_3channel);
		motion.draw(binary_mat_3channel);
		imshow(string, binary_mat_3channel);
		waitKey(10);    // 等待显示
	}

	void display_window(Racing & racing,Parking & park,Danger & danger,Rescue & rescue,Circle & circle,Motion & motion,control & control,track & track, string string , Scene scene)
	{
		Mat binary_mat_3channel;
		cvtColor(track.binary_mat, binary_mat_3channel, cv::COLOR_GRAY2BGR); 
		track.drawImage(binary_mat_3channel);
		control.draw_mid_line(binary_mat_3channel);
		motion.draw(binary_mat_3channel);
		// circle.draw(binary_mat_3channel);
	if(motion.params.cross)
	{
		switch (scene)
		{
		case RescueScene:
			rescue.draw(binary_mat_3channel);
		break;
		case DangerScene:
			danger.draw(binary_mat_3channel);
		break;
		case ParkingScene:
			park.draw(binary_mat_3channel);
		break;
		case RacingScene:
			racing.draw(binary_mat_3channel);
		break;
		}
	}
		cv::Size newSize(3*COLSIMAGE, 3*ROWSIMAGE);
		cv::Mat resizedImage;  
		cv::resize(binary_mat_3channel, resizedImage, newSize); 
  		imshow(string, resizedImage);
		waitKey(10);    // 等待显示
	}
};